﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;
namespace HNQXYJ.HN_DATA
{
    public partial class ProvinceLEDStatistics : System.Web.UI.Page
    {
        public static List<HCity> list;
        public string returnValue = "";
        public string xAxisCategories = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            xAxisCategories = GetCountyLists();
            returnValue = GetDataString();
        }

        //获取每个城市的名称
        public string GetCountyLists()
        {
            //rankLevel = Session["ranklevel"].ToString();//用来在县级表中提取该代码下对应的县
            list = new CityBLL().GetCityListAll();
            string s = "[' 河南省 ','";
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (i < list.Count - 1)
                    {
                        s += list[i].Name + "','";
                    }
                    else
                    {
                        s += list[i].Name + "']";
                    }
                }
            }
            return s;
        }

        //获取对应城市的数据
        public string GetDataString()
        {
            string s = "";
            int[] dataAll = new int[list.Count + 1];
            int[] dataOnline = new int[list.Count + 1];
            int[] dataOffline = new int[list.Count + 1];

            dataAll[0] = TerminalBLL.GetNumberALLByRankLevel(1 + "%", "1");
            dataOnline[0] = TerminalBLL.GetNumberByStatusAndCounty("在线", 1 + "%", "1");
            dataOffline[0] = TerminalBLL.GetNumberByStatusAndCounty("离线", 1 + "%", "1");

            for (int i = 1; i < dataAll.Length; i++)
            {
                dataAll[i] = TerminalBLL.GetNumberALLByRankLevel(list[i - 1].SelfCode + "%", "1");
                dataOnline[i] = TerminalBLL.GetNumberByStatusAndCounty("在线", list[i - 1].SelfCode + "%", "1");
                dataOffline[i] = TerminalBLL.GetNumberByStatusAndCounty("离线", list[i - 1].SelfCode + "%", "1");
            }
            s += "[{name: '终端总数量',data:" + GetDataArray(dataAll) + "}, {name: '终端在线数量',data:" + GetDataArray(dataOnline) + "}, {name: '终端离线数量',data: " + GetDataArray(dataOffline) + "}]";

            return s;
        }

        //拼接城市数据的字符串
        public string GetDataArray(int[] a)
        {
            string data = "[";
            for (int i = 0; i < a.Length; i++)
            {
                if (i < a.Length - 1)
                {
                    data += a[i] + ",";
                }
                else
                {
                    data += a[i] + "]";
                }
            }
            return data;
        }
    }
}